package com.zhiyou.app.shop.common.util;


import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import java.util.Random;

public class Page implements Serializable
{

	private static final long serialVersionUID = 1L;

	/**
	 * 当前页数
	 */
	private Integer pageNo=1;
	
	/**
	 * 每页显示数据数量
	 */
	private Integer pageSize=30;
	
	/**
	 * 显示的是当前位置
	 */
	private Integer offset=0;

	
	/**
	 * 统计出来的所有数据
	 */
	private Integer totalCount;
	/**
	 * 总页数
	 */
	private Integer totalPageCount;
	
	/**
	 * 分页数据集合
	 */
	private List result;

	public Page(int pageNo, int pageSize)
	{
		this.pageNo = pageNo;
		if(pageSize>0){
			this.pageSize = pageSize;
		}
    	this.offset = this.pageNo != null ? (this.pageNo-1) * this.pageSize : 0;
	}
	
	public Page(List result, int pageNo, int pageSize, int totalCount)
	{
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.result = result;
		this.totalCount = totalCount;
    	this.offset = this.pageNo != null ? (this.pageNo-1) * pageSize : 0;
	}

	public Integer getPageNo() 
	{
		return pageNo;
	}

	public void setPageNo(Integer pageNo) 
	{
		this.pageNo = pageNo;
	}

	public Integer getPageSize() 
	{
		return pageSize;
	}

	public void setPageSize(Integer pageSize) 
	{
		this.pageSize = pageSize;
	}

	public Integer getOffset() 
	{
		return offset;
	}

	public void setOffset(Integer offset) 
	{
		this.offset = offset;
	}


	public void setTotalCount(Integer totalCount) 
	{
		this.totalCount = totalCount;
	}

	public List getResult() 
	{
		return result;
	}

	public void setResult(List result) 
	{
		this.result = result;
	}

	/**
	 * @return the totalPageCount
	 */
	public Integer getTotalPageCount() {
		if(this.getTotalCount()!=null){
			int totPage = this.getTotalCount()%this.pageSize!=0?this.getTotalCount()/this.pageSize+1:this.getTotalCount()/this.pageSize;
			return totPage;
		}
		return 0;
	}

	/**
	 * @param totalPageCount the totalPageCount to set
	 */
	public void setTotalPageCount(Integer totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	/**
	 * @return the totalCount
	 */
	public Integer getTotalCount() {
		return totalCount;
	}
	
	public static void main(String[] args) {
		Page page = new Page(1,10);
		page.setTotalCount(1);
		System.out.println(page.getTotalPageCount());
		//1000000---9999999
		//0-8999999
		Random rand = new Random();
		System.out.println(1000000 + rand.nextInt(8999999)+"");
		
		Timestamp time = new Timestamp(System.currentTimeMillis());
		System.out.println(time.toString());
		
		Object ll = new Long(2);
		Integer a = ((Long)(ll)).intValue();
	}
}
